﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace SplenetiX
{
    [Serializable]
    public enum CharacterType
    {
        Personnage, Ennemi, Null
    }

    [Serializable]
    public class Character : Sprite
    {
        protected bool isOnGround, isJumping, doubleSaut;
        protected Vector2 vitesse;
        protected List<Projectile> projectiles;
        protected float previousBottom;
        protected CharacterType type;

        public CharacterType Type
        {
            get { return type; }
        }

        public float PreviousBottom
        {
            get { return previousBottom; }
            set { previousBottom = value; }
        }

        public bool IsOnGround
        {
            get { return isOnGround; }
            set { this.isOnGround = value; }
        }
        public bool IsJumping
        {
            get { return isJumping; }
            set { isJumping = value; }
        }

        public Vector2 Vitesse
        {
            get { return vitesse; }
            set { vitesse = value; }
        }

        public List<Projectile> Projectiles
        {
            get { return projectiles; }
        }

        //Constructeur
        protected Character(Vector2 position)
            : base(position)
        {
            vitesse = Vector2.Zero;
            projectiles = new List<Projectile>();
            isOnGround = false;
            isJumping = false;
            doubleSaut = false;
            type = CharacterType.Null;
        }

        //Constructeur
        protected Character(Vector2 position, CharacterType type)
            : base(position)
        {
            vitesse = Vector2.Zero;
            projectiles = new List<Projectile>();
            isOnGround = false;
            isJumping = false;
            doubleSaut = false;
            this.type = type;
        }

        protected void Move(float deltaT)
        {
            //Chute libre
            if (isOnGround)
            {
                vitesse.Y = 0;
            }
            else
            {
                vitesse.Y += Constant.Gravity * deltaT;
            }

            UpdatePosition(new Vector2(0, vitesse.Y));

            if (isJumping)
            {
                if (vitesse.Y <= 0)
                {
                    isJumping = false;
                }
            }

            if (vitesse.Y > Constant.MaxFallSpeed)
            {
                vitesse.Y = Constant.MaxFallSpeed;
            }
        }

        protected void Jump()
        {
            vitesse.Y = -Constant.JumpIntensity;
            isOnGround = false;
            isJumping = true;
        }

        //Debug crade
        public virtual void StopFollow()
        {
        }
        public virtual void IA(Level level)
        {
        }
        //End Debug crade
    }
}
